package com.fund.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;

public interface BaseEnum{
    Integer getValue();

    @JsonCreator
    static <E extends BaseEnum> E fromCode(Class<? extends BaseEnum> enumClass, Integer code) {
        if (code == null) {
            return null;
        }
        for (BaseEnum e : enumClass.getEnumConstants()) {
            if (e.getValue().equals(code)) {
                return (E) e;
            }
        }
        throw new IllegalArgumentException("未知的枚举code: " + code + " for " + enumClass.getSimpleName());
    }
}
